"""
3031. 二进制倒置
Time limit per test: 2.0 seconds

Memory limit: 256 megabytes

给定一个整数 n(0≤n≤10^100)、将 n 的 334 位二进制表示形式（不包括开头可能的值为 0 的位，n=0 表示为 1 位 0）前后倒置，输出倒置后的二进制数对应的整数。

例如：n=10，其二进制表示为 (330 个 0)1010，倒置后为 0101，对应输出就是 5。

Input
第 1 行：一个整数 T (1≤T≤10) 为问题数。

接下来共 T 行整数，对应每个问题有 1 行，表示 n。

Output
对于每个问题，输出一行问题的编号（0 开始编号，格式：case #0: 等）。

然后对应每个问题在一行中输出结果。

Examples
input
3
10
0
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
output
case #0:
5
case #1:
0
case #2:
7715442851596369463000695959966459436485038766875199595258933941809737
Hints
十进制10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000的334位二进制表示为：
0100100100100110101101001001011001010011000011011111001110101100001011001001111000010011000100110011100000101111110011100010101100111001000000100011100010000100011010011111001010101010110010010000110000100010101000001011101000111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000，
不包括开头的 1个0为：
100100100100110101101001001011001010011000011011111001110101100001011001001111000010011000100110011100000101111110011100010101100111001000000100011100010000100011010011111001010101010110010010000110000100010101000001011101000111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000，
倒置后为：
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001111000101110100000101010001000011000010010011010101010100111110010110001000010001110001000000100111001101010001110011111101000001110011001000110010000111100100110100001101011100111110110000110010100110100100101101011001001001001，
对应十进制值为：
7715442851596369463000695959966459436485038766875199595258933941809737
"""

def dec2bin(dec):
    bin = 0
    n = 1
    while dec>0:
        bin += (dec % 2)*n
        dec //= 2
        n *= 10
    return bin

def backbin2dec(bin):
    dec = 0
    while bin>0:
        dec = dec*2 + bin%10
        bin //= 10
    return dec

qnum = int(input())
for i in range(qnum):
    dec = int(input())
    bin = dec2bin(dec)
    dec = backbin2dec(bin)
    print("case #{:d}:".format(i))
    print(dec)
